<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0">
    <title>滑块</title>
    <script src="../node_modules/vue/dist/vue.min.js"></script>
    <style>
        .switch__core{
            margin: 0;
            display: inline-block;
            position: relative;
            width: 40px;
            height: 20px;
            border: 1px solid #dcdfe6;
            outline: none;
            border-radius: 10px;
            box-sizing: border-box;
            background: #dcdfe6;
            cursor: pointer;
            transition: border-color .3s,background-color .3s;
            vertical-align: middle;
        }
        .switch__core:after{
            content: "";
            position: absolute;
            top: 1px;
            left: 1px;
            border-radius: 100%;
            transition: all .3s;
            width: 16px;
            height: 16px;
            background-color: #fff;
        }
        .switch__on{
            border-color: rgb(19, 206, 102);
            background-color: rgb(19, 206, 102);
        }
        .switch__off{
            border-color: rgb(255, 73, 73);
            background-color: rgb(255, 73, 73);
        }
        .switch.is-checked .switch__core:after {
            left: 100%;
            margin-left: -17px;
        }
    </style>
</head>
<body>
<div id="app">
    <div :class="['switch', {'is-checked': isChecked}]" :aria-checked="true" @click="changeSwitch">
        <span :class="['switch__core', switchValue]"></span>
    </div>
</div>
<script>
  new Vue({
    el: '#app',
    data() {
      return {
        isChecked: false
      }
    },
    computed:{
      switchValue(){
        return this.isChecked?'switch__off': 'switch__on'
      }
    },
    methods: {
      changeSwitch(){
        this.isChecked = !this.isChecked
      }
    }
  })
</script>
</body>
</html>
